################################
# setup and proc
# ##############################
source -e -v user_scripts/global_setup.tcl
source -e -v user_scripts/block_setup.tcl
source -e -v user_scripts/loadInnovus.tcl

set current_step "floorplan"
set previous_step "import"

set report_dir "reports/${current_step}"
if {![file exist $report_dir]} {file mkdir $report_dir}

#####################################
# open design
# ##################################
restoreDesign ${DESIGN_LIBRARY}/${DESIGN_NAME}.${previous_step}.dat $DESIGN_NAME

# common setting
source -e -v user_scripts/common_setting.tcl


########################################
# initial floorplan
# #####################################
set die_width 0
set die_height 0
foreach point $DIE_BOUNDARY {
		set x [lindex $point 0]
		set y [lindex $point 1]
		if {$x > $die_width} {set die_width $x}
		if {$y > $die_height} {set die_height $y}
}

puts "INFO: DIE WIDTH: $die_width, DIE HEIGHT: $die_height"

#SIZE 0.400 BY 2.760
set core2die_left 0.40
set core2die_bottom 5.52
set core2die_right 0.40
set core2die_top 5.52

#for rectangle
#floorplan -coreMarginsBy die -noSnapToGrid -d $die_width $die_height $core2die_left $core2die_bottom $core2die_right $core2die_top
setIoFlowFlag 1
#floorPlan -site sc9mc_40ulpeflash -d 1285.0 1285.0 20.03 20.09 20.03 20.09 -noSnapToGrid
#floorPlan -site CORE -d 2700 1400 20.03 20.09 20.03 20.09 -noSnapToGrid
#floorPlan -site CORE -d 2700 1400 22 22 22 22 -noSnapToGrid
floorPlan -site CORE -d 2140 1940 35 35 35 35 -noSnapToGrid

#for rectilinear
if {[llength $DIE_BOUNDARY] > 5} {
		regsub -all "\{|\}" $DIE_BOUNDARY {} poly
		setObjFPlanPolygon cell [dbGet top.name] $poly
}

############################################
# pin placement
############################################
if {[file exists $PIN_PLACEMENT_FILE]} {
		puts "INFO: Sourcing $PIN_PLACEMENT_FILE"
		source -echo $PIN_PLACEMENT_FILE
} elseif {$PIN_PLACEMENT_FILE != ""} {
		puts "error: PIN_PLACEMENT_FILE($PIN_PLACEMENT_FILE) is invalid. Pls correct it."
}

############################################
# macro placement
############################################
if {[file exists $MACRO_PLACEMENT_FILE]} {
		puts "INFO: Sourcing $MACRO_PLACEMENT_FILE"
		source -echo $MACRO_PLACEMENT_FILE
} elseif {$MACRO_PLACEMENT_FILE != ""} {
		puts "error: MACRO_PLACEMENT_FILE($MACRO_PLACEMENT_FILE) is invalid. Pls correct it."
}

saveDesign ${DESIGN_LIBRARY}/${DESIGN_NAME}.init_floorplan

############################################
#Pre-floorplan customizations
############################################
if {[file exists $PRE_SCRIPT($current_step)]} {
		puts "INFO: Sourcing $PRE_SCRIPT($current_step)"
		source $PRE_SCRIPT($current_step)
} else {
		puts "WARN: $PRE_SCRIPT($current_step) not exist. Skip to source it."
}


############################################
# placement blockage
############################################
source -e user_scripts/placement_blockage.tcl


############################################
# Boundary cells
############################################
#source -e user_scripts/add_boundary_cell.tcl

############################################
# tap cells
############################################
#source -e user_scripts/add_tap_cell.tcl


############################
# PG connection
# ##########################
source -e -v user_scripts/pg_connection.tcl



############################################
#Power and Ground network
############################################
if {[file exists $POWERPLAN_FILE]} {
		puts "INFO: Sourcing $POWERPLAN_FILE"
		source -e $POWERPLAN_FILE
} elseif {$POWERPLAN_FILE != ""} {
		puts "error: POWERPLAN_FILE($POWERPLAN_FILE) is invalid. Pls correct it."
}






#####################################
# Post-init_design customizations
# ##################################
if {[file exists $POST_SCRIPT($current_step)]}  {
		puts "INFO: Sourcing $POST_SCRIPT($current_step)"
		source $POST_SCRIPT($current_step)
} else {
		puts "WARN: $POST_SCRIPT($current_step) not exist. Skip to source it."
}


saveDesign ${DESIGN_LIBRARY}/${DESIGN_NAME}.${current_step}


###################################################
# Report
# ##############################################
if {$REPORT_QOR($current_step)} {
		source -e ./user_scripts/report_qor.tcl
} else {
		puts "INFO: Skip report for step: $current_step"
}

date > ${current_step}

exit






